package org.lzy.shop.adapter

import android.content.Context
import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatRatingBar
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.QuickViewHolder
import org.lzy.shop.R
import org.lzy.shop.response.Comment
import org.lzy.shop.response.ListDTO

import org.lzy.shop.util.setUrl
import org.lzy.shop.util.setUrlRound

class CommentAllAdapter: BaseQuickAdapter<ListDTO, QuickViewHolder>()  {


    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): QuickViewHolder {
        return QuickViewHolder(R.layout.item_comment_all, parent)
    }

    override fun onBindViewHolder(holder: QuickViewHolder, position: Int, item: ListDTO?) {
        item?.let {
            setUrlRound(item.avatarUrl,60f,holder.getView(R.id.comment_iv_icon))
            holder.setText(R.id.comment_nickname, item.nickName)
            holder.setText(R.id.comment_content, item.content)
            holder.setText(R.id.comment_time, item.createTime)
            val ratingBar = holder.getView<AppCompatRatingBar>(R.id.comment_ratingbarnum)
            ratingBar.numStars=item.starCount
            val  orderPicAdapter=OrderPicAdapter()
            val  shopPicRv = holder.getView<RecyclerView>(R.id.pic_rv)
            shopPicRv.apply {
                layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
                adapter=orderPicAdapter
            }
            if (item.pics.isNotEmpty()) {
                orderPicAdapter.submitList(item.pics)
            }
        }


    }


}